using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PACKETPARSERMAX20.CORE;

namespace PACKETPARSERMAX20.CORE.DEFINITIONS
{
    public class SMSG_GAMEOBJECT_QUERY_RESPONSE_DEF : DefinitionBase
    {


        public override bool Process()
        {
            ResetPosition();
            if (AvailableBytes < 12) 
            { 
                base.Warning = "CORRUPT PACKET."; 
                return false; 
            }

            var template = GetGameObjectTemplate();

            GlobalCache.AddGameObjectTemplateSum(template, ClientBuild);

 
            return Validate();
        }

        public gameobject_template GetGameObjectTemplate()
        {
            var template = new gameobject_template();

            template.entry = ReadUInt32();
            template.type = (byte)ReadUInt32();
            template.displayid = ReadUInt32();

            template.name = ReadString();
            ReadString();// name2, name3, name4
            ReadString();
            ReadString();
            template.iconname = ReadString();// 2.0.3, string
            template.castbarcaption = ReadString();// 2.0.3, string
            template.unk1 = ReadString();// 2.0.3, probably string

            template.data0 = ReadUInt32();
            template.data1 = ReadUInt32();
            template.data2 = ReadUInt32();
            template.data3 = ReadUInt32();
            template.data4 = ReadUInt32();
            template.data5 = ReadUInt32();
            template.data6 = ReadUInt32();
            template.data7 = ReadUInt32();
            template.data8 = ReadUInt32();
            template.data9 = ReadUInt32();
            template.data10 = ReadUInt32();
            template.data11 = ReadUInt32();
            template.data12 = ReadUInt32();
            template.data13 = ReadUInt32();
            template.data14 = ReadUInt32();
            template.data15 = ReadUInt32();
            template.data16 = ReadUInt32();
            template.data17 = ReadUInt32();
            template.data18 = ReadUInt32();
            template.data19 = ReadUInt32();
            template.data20 = ReadUInt32();
            template.data21 = ReadUInt32();
            template.data22 = ReadUInt32();

            if (ClientBuild >= 8606)
            {
                template.data23 = ReadUInt32();
            }

            template.size = ReadSingle();

            if (ClientBuild > 9551)
            {
                template.questitem1 = ReadUInt32();
                template.questitem2 = ReadUInt32();
                template.questitem3 = ReadUInt32();
                template.questitem4 = ReadUInt32();
                if (ClientBuild >= 10314)
                {
                    template.questitem5 = ReadUInt32();
                    template.questitem6 = ReadUInt32();
                }
            }

            return template;
        }
    }
}
